package com.www.applyword.ui.home;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.allen.library.SuperTextView;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.HotJobAdapter2;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.ComInfoBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.utils.ImageUtil;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2019/11/9 0009 10:30
 * version: 1.0
 */
public class CompanyInfoActivity extends BaseActivity {
    @BindView(R.id.st_company)
    SuperTextView stCompany;
    @BindView(R.id.ll_bond)
    LinearLayout llBond;
    @BindView(R.id.tv_com1)
    TextView tvCom1;
    @BindView(R.id.tv_com2)
    TextView tvCom2;
    @BindView(R.id.tv_com3)
    TextView tvCom3;
    @BindView(R.id.tv_com4)
    TextView tvCom4;
    @BindView(R.id.tv_com5)
    TextView tvCom5;
    @BindView(R.id.tv_com6)
    TextView tvCom6;
    @BindView(R.id.tv_com7)
    TextView tvCom7;
    @BindView(R.id.tv)
    TextView tv;
    @BindView(R.id.ll)
    LinearLayout ll;
    @BindView(R.id.rl_fabu_job)
    RecyclerView rlFabuJob;

    private HotJobAdapter2 mHotJobAdapter;
    private int type2;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.company_info_activity);
        setTitle("公司详情");

    }

    @Override
    protected void loadData() {
        type2 = getIntent().getIntExtra("type", 0);
        if (type2 == 1){
            setTitle("个人详情");
        }
        rlFabuJob.setLayoutManager(new LinearLayoutManager(this));
        rlFabuJob.setItemAnimator(new DefaultItemAnimator());
        mHotJobAdapter = new HotJobAdapter2(this);
        rlFabuJob.setAdapter(mHotJobAdapter);

        Map<String, Object> params = new HashMap<>();
        params.put("OrderID", getIntent().getStringExtra("OrderID"));
        params.put("Page", "1");
        params.put("Rows", "10");
        // 0 是公司
        params.put("Type", getIntent().getIntExtra("type", 0) + "");

        HttpClient.get(CompanyInfoActivity.this, Constants.GETUSERORCOMPANYINFORMATION, params, new CallBack<ComInfoBean>() {
            @Override
            public void onSuccess(ComInfoBean result) {
                if (type2 == 1){
                    tvCom1.setText("姓名: " + result.getOrder().getOrder_BusinessName());
                    tvCom2.setText("手机号: " + result.getOrder().getOrder_ContactsPhone());
                    llBond.setVisibility(View.GONE);
                    tvCom3.setVisibility(View.GONE);
                    tvCom4.setVisibility(View.GONE);
                    tvCom5.setVisibility(View.GONE);
                }else {
                    tvCom1.setText("企业类型: " + result.getEnterpriseCertification().getEnterpriseCertification_EnterpriseTypeName());
                    tvCom2.setText("行业类型: " + result.getEnterpriseCertification().getEnterpriseCertification_IndustryName());
                    tvCom3.setText("注册地址: " + result.getEnterpriseCertification().getEnterpriseCertification_Address());
                    tvCom4.setText("统一社会信用代码: " + result.getEnterpriseCertification().getEnterpriseCertification_CreditCode());
                    tvCom5.setText("人员规模: " + result.getEnterpriseCertification().getEnterpriseCertification_People());
                }

                mHotJobAdapter.replaceAll(result.getOrderList(), true);
                if (!TextUtils.isEmpty(result.getEnterpriseCertification().getEnterpriseCertification_ID())) {
                    ImageUtil.setImage(stCompany.getLeftIconIV(), result.getEnterpriseCertification().getEnterpriseCertification_Logo());
                    stCompany.getLeftTopTextView().setText(result.getEnterpriseCertification().getEnterpriseCertification_Name());
                    stCompany.getLeftBottomTextView().setText("联系人: " + result.getEnterpriseCertification().getEnterpriseCertification_UserName());
                    tvCom7.setText(result.getEnterpriseCertification().getEnterpriseCertification_Introductions());
                } else {
                    ImageUtil.setImage(stCompany.getLeftIconIV(), result.getUser().getUserInfo_HeadImg());
                    stCompany.getLeftTopTextView().setText(result.getUser().getUserInfo_NickName());
                    stCompany.getLeftBottomTextView().setText("联系人: " + result.getUser().getUserInfo_RealName());
                    tvCom7.setVisibility(View.GONE);
                    //公司性质
                    ll.setVisibility(View.GONE);
                }

                mHotJobAdapter.setOnItemClickListener((viewHolder, view, i) ->
                        startActivity(new Intent(CompanyInfoActivity.this, HotJobDetailsActivity.class)
                                .putExtra("OrderID", mHotJobAdapter.getItem(i).getOrder_ID())));
            }
        });
    }
}
